package com.cloudnote.web.util.timertask;
//package com.sima.christmas.util.timertask;
//
//import com.jasson.im.api.MOItem;
//import com.sima.christmas.model.Tsmoriginalappeal;
//import com.sima.christmas.service.SMSSentServiceI;
//import com.sima.christmas.service.SmOriginalAppealServiceI;
//import com.sima.christmas.service.impl.SMSSentServiceImpl;
//import com.sima.christmas.service.impl.SmOriginalAppealServiceImpl;
//import com.sima.christmas.util.SMSUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//
//import java.io.UnsupportedEncodingException;
//import java.util.Date;
//import java.util.TimerTask;
//
///**
// * Created by 锋情 on 2014-08-18.
// */
//public class ReceiveSMTask extends TimerTask {
//
//    @Autowired
//    private SmOriginalAppealServiceI smOriginalAppealService;
//    @Autowired
//    private SMSSentServiceI smsSentService;
//    private String mobileString = "";
//    private StringBuilder mobileBuilder = null;
//    //    Tsmoriginalappeal tsmoriginalappeal = null;
//    MOItem[] moItems = null;
//
//    public ReceiveSMTask() {
//        smOriginalAppealService = new SmOriginalAppealServiceImpl();
//        smsSentService = new SMSSentServiceImpl();
//        mobileBuilder = new StringBuilder();
//
//    }
//
//    @Override
//    public void run() {
//        System.out.println("Receive SM Start .....");
//        moItems = SMSUtils.receiveSM();
//        if (moItems == null) {
//            System.out.println("接收失败！");
//            return;
//        }
//
//        if (moItems.length > 0) {
//            int count = 1;
//            String smContent = "";
//            for (MOItem m : moItems) {
////                System.out.println("接收数据: " + m.toString());
//                try {
//                    smContent = new String(m.getContent().getBytes(), "utf-8");
//                } catch (UnsupportedEncodingException e) {
//                    e.printStackTrace();
//                }
//                System.out.println("第" + count + "条短信");
//                System.out.println("getContent: " + smContent);
//                System.out.println("getMobile: " + m.getMobile());
//                Tsmoriginalappeal tsmoriginalappeal = new Tsmoriginalappeal(m.getMobile(), smContent, new Date());
//                //原始诉求添加成功
//                if (smOriginalAppealService.add(tsmoriginalappeal)) {
//                    mobileBuilder.append(m.getMobile() + ";");
//                }
//                count++;
//            }
//            if (!mobileBuilder.toString().isEmpty()) {
//                mobileString = mobileBuilder.toString().substring(0, mobileBuilder.toString().length() - 1);
//                System.out.println("mobileString: " + mobileString);
//                String[] mobiles = mobileString.split(";");
//                mobileBuilder.delete(0, mobileBuilder.length());
//                int result = SMSUtils.sendSM(mobiles, "您的诉求已经收到，我们会尽快处理！", new Long(22));
//                if (result == SMSUtils.apiClient.IMAPI_SUCC) {
//                    System.out.println("IMAPI_SUCC");
//                    //添加发送记录 rar 当收到诉求后回复本短信
//                    for (String tel :mobiles){
//                        Boolean smsres = smsSentService.addJDBC("rar", tel, "您的诉求已经收到，我们会尽快处理！");
//                    }
//
//                } else if (result == SMSUtils.apiClient.IMAPI_INIT_ERR){
//                    System.out.println("IMAPI_INIT_ERR");
//                }else if (result == SMSUtils.apiClient.IMAPI_CONN_ERR){
//                    System.out.println("IMAPI_CONN_ERR");
//                }else if (result == SMSUtils.apiClient.IMAPI_DATA_ERR){
//                    System.out.println("IMAPI_DATA_ERR");
//                }else if (result == SMSUtils.apiClient.IMAPI_DATA_TOOLONG){
//                    System.out.println("IMAPI_DATA_TOOLONG");
//                }else if (result == SMSUtils.apiClient.IMAPI_INS_ERR){
//                    System.out.println("IMAPI_INS_ERR");
//                }else if (result == SMSUtils.apiClient.IMAPI_IFSTATUS_INVALID){
//                    System.out.println("IMAPI_IFSTATUS_INVALID");
//                }else if (result == SMSUtils.apiClient.IMAPI_GATEWAY_CONN_ERR){
//                    System.out.println("IMAPI_GATEWAY_CONN_ERR");
//                }else{
//                    System.out.println("other_err");
//                }
//            }
//
//        } else {
//            System.out.println("暂无数据 .....");
//        }
//
//
//        System.out.println("Receive SM Over .....");
//    }
//}
